﻿Imports System.Collections.Specialized
Imports System.IO
Imports System.Globalization
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client
Imports System.Collections.ObjectModel
Imports System
Imports System.ComponentModel
Imports System.Xml.Serialization
Imports System.Threading
Imports Microsoft.TeamFoundation.WorkItemTracking.Controls
Imports System.Text

Partial Public Class CreateWorkItem

    Private m_wifceh As WorkItemFieldChangeEventHandler
    Private m_wiip As WorkItemInformationProvider

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        m_wifceh = New WorkItemFieldChangeEventHandler(AddressOf Me.WorkItemChanged)
        m_wiip = New WorkItemInformationProvider(Me.uxWorkItemFormControl, String.Empty, "0")


    End Sub

    Private Sub CreateWorkItem_DataContextChanged(ByVal sender As Object, ByVal e As System.Windows.DependencyPropertyChangedEventArgs) Handles Me.DataContextChanged
        Me.uxWorkItemFormControl.Item = Me.DataContext
        AddHandler Me.uxWorkItemFormControl.Item.FieldChanged, AddressOf WorkItemChanged
    End Sub

    Public Sub WorkItemChanged(ByVal sender As Object, ByVal e As WorkItemEventArgs)
        Me.SetTitleText(Me.uxWorkItemFormControl.Item)

    End Sub

    Public Sub dosave()
        Dim list As ArrayList = Me.uxWorkItemFormControl.Item.Validate
        If (list.Count > 0) Then
            Dim builder As New StringBuilder
            builder.AppendFormat("There are {0} fileds with errors: ", list.Count)
            builder.AppendLine()
            Dim field As Field
            For Each field In list
                builder.AppendLine(field.Name)
            Next
            uxWorkItemInformationBar.Text = builder.ToString
            uxWorkItemInformationBar.StartMarquee(1000)
        Else
            Dim c As ICommand = Controlers.TeamSystemCommands.SaveWorkItemCommand
            c.Execute(Me.uxWorkItemFormControl.Item)
        End If
    End Sub

    Private Sub SetTitleText(ByVal paramWI As WorkItem)
        Me.uxWorkItemInformationBar.Refresh(Me.m_wiip)
    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        dosave()
    End Sub
End Class
